package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.venueservice.dto.LoadInfoDTO;
import com.eastfair.venueservice.dto.LoadInfoExamineDTO;
import com.eastfair.venueservice.dto.LoadInfoPageQuery;
import com.eastfair.venueservice.entity.LoadInfo;
import com.eastfair.venueservice.service.LoadInfoService;
import com.eastfair.venueservice.vo.LoadInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 智慧物流 装卸服务
 *
 * @author Du Xiaobo
 * @date 2023/5/8 14:20
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/logistics/load")
@Api(value = "LogisticsLoad", tags = "智慧物流-装卸服务")
@PreAuth(replace = "common:logisticsload:")
public class LoadController extends SuperController<LoadInfoService, Long, LoadInfo, LoadInfoPageQuery, LoadInfoDTO, LoadInfoDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private LoadInfoService loadInfoService;


    @Override
    public void handlerResult(IPage<LoadInfo> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list) {
        List<LoadInfo> loadInfoList = list
                .stream()
                .map((map) -> LoadInfo.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(loadInfoList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<LoadInfoPageQuery> params) {
        LoadInfoPageQuery pageQuery = params.getModel();
    }

    @SysLog("新增装卸服务信息")
    @PostMapping("/save")
    @ApiOperation(value = "新增装卸服务信息", notes = "新增装卸服务信息")
    public R<Long> saveLoadInfo(@RequestBody LoadInfoDTO dto) {
        return R.success(loadInfoService.saveLoadInfo(dto));
    }

    @SysLog("修改装卸服务信息")
    @PostMapping("/update")
    @ApiOperation(value = "修改装卸服务信息", notes = "修改装卸服务信息")
    public R updateLoadInfo(@RequestBody LoadInfoDTO dto) {
        loadInfoService.updateLoadInfo(dto);
        return R.success();
    }

    @SysLog("查询装卸服务详情")
    @GetMapping("/get/{id}")
    @ApiOperation(value = "查询装卸服务详情", notes = "查询装卸服务详情")
    public R<LoadInfoVo> getLoadInfoById(@PathVariable("id") Long id) {
        return R.success(loadInfoService.getLoadInfoById(id));
    }

    @SysLog("查询装卸服务列表")
    @ApiOperation("查询装卸服务列表VO")
    @PostMapping("/query/page")
    public R<Page<LoadInfoVo>> queryLoadInfo(@RequestBody PageParams<LoadInfoPageQuery> pageParams) {
        log.info("queryLoadInfo - 查询装卸服务列表VO, pageParams={}", pageParams);
        Page<LoadInfoVo> page = loadInfoService.listLoadInfo(pageParams);
        return R.successDef(page);
    }

    @SysLog("装卸服务审核")
    @PostMapping("/examine")
    @ApiOperation("装卸服务审核")
    public R<Boolean> examine(@RequestBody LoadInfoExamineDTO dto) {
        return R.success(loadInfoService.examine(dto));
    }
    // 删除装卸服务

}
